package com.hoangkien.network.task;

import java.io.IOException;
import org.apache.http.client.ClientProtocolException;
import org.json.JSONException;
import com.hoangkien.config.ICore;
import com.hoangkien.network.IProtocol;
import com.hoangkien.network.request.GetListProductRequest;
import com.hoangkien.network.response.GetListPromotionResponse;
import com.hoangkien.util.Listener;

public class TaskGetListPromotions extends AbstractTask {
	int pageNumber;
	int pageLimit;
	public TaskGetListPromotions(Listener listener, ICore core, int pageLimit,int pageNumber) {
		super(listener, core);
		this.pageLimit = pageLimit;
		this.pageNumber= pageNumber;
	}

	@Override
	public void run() throws ClientProtocolException, JSONException,IOException {
		GetListProductRequest request= new GetListProductRequest();
		request.setPageLimit(pageLimit);
		request.setPageNumber(pageNumber);
		GetListPromotionResponse response= protocol.getListPromos(request);
		for(Listener mListener:listener){
			mListener.finishGetListPromos(response.getReturnCode(),response.getCountPage() , response.getListPromos());
		}
		
	}

	@Override
	public void timeoutCallback() {
		for(Listener mListener:listener){
			mListener.finishGetListPromos(IProtocol.STATUS_CODE_GENERIC_FAIL_CONECTTION,0, null);
		}
		
	}

}
